<template>
    <div class="header">
      <div class="detail-header" v-show="showHeader">
        <span class="header-radius"></span>
        <span  class="header-return iconfont" @click="toHome">&#xe611;</span>
      </div>
      <div class="header-top"
           v-show="!showHeader"
           :style="styleOpacity"
      >
        <div class="header-left">
          <span class="iconfont" @click="toHome">&#xe611;</span>
        </div>
        故宫
      </div>
    </div>
</template>

<script>
    export default {
        name: "Header",
        data(){
          return{
            showHeader:true,
            styleOpacity:{
              opacity:0
            }
          }
        },
      methods:{
          toHome(){
            this.$router.push('/')
          }
      },
      mounted() {
          let That = this
          window.addEventListener("scroll",function () {
           let top = document.documentElement.scrollTop;
           if (top>45){
             let opacity = top/130
             opacity=opacity>1 ? 1 :opacity
             That.styleOpacity={opacity}
             That.showHeader =false;
           }
           else {
             That.showHeader=true;
           }
          })
      }
    }
</script>

<style scoped lang="stylus">
  @import "~css/var.styl"
  .detail-header{
    position: absolute;
    left: .1rem;
    top: .1rem;
    width: .72rem;
    height: .72rem;
  }
  .header-radius{
    display: block;
    width: .72rem;
    height: .72rem;
    background-color: #000;
    opacity: .5;
    border-radius: .36rem;
  }
  .header-return{
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    width: .72rem;
    line-height: .72rem;
    text-align: center;
    color: #fff;
  }
  .header-top{
    position:fixed;
    top:0;
    text-align:center;
    width: 100%;
    line-height: .88rem;
    background: $bgColor;
    color: #ffffff;
    font-size: .36rem;
  }
  .header-left{
    position:absolute;
    width: .4rem;
    padding: 0 .2rem;
    text-align: center;
    font-weight: bold;
  }
</style>
